/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __SYMAP_H__
#define __SYMAP_H__

#include <vector>

namespace liba
{

template<typename A, typename B>
class Symap
{
	A default_a;
	B default_b;
	struct pair
	{
		A a;
		B b;
		pair()
		{}
		pair( const A & a, const B & b )
			:	a( a ),
				b( b )
		{}
	};
	std::vector< pair > tab;
public:
	Symap( const A & default_a, const B & default_b )
		:	default_a( default_a ),
			default_b( default_b )
	{}
	void add( const A & a, const B & b )
	{
		tab.push_back( pair(a,b) );
	}

	const A & get_first_by_second( const B & b )const
	{
		typename std::vector< pair >::const_iterator it = tab.begin();
		for( ; it != tab.end(); ++it )
			if( it->b == b )
				return it->a;
		return default_a;
	}
	const B & get_second_by_first( const A & a )const
	{
		typename std::vector< pair >::const_iterator it = tab.begin();
		for( ; it != tab.end(); ++it )
			if( it->a == a )
				return it->b;
		return default_b;
	}

	bool is_exists_second( const B & b )const
	{
		typename std::vector< pair >::const_iterator it = tab.begin();
		for( ; it != tab.end(); ++it )
			if( it->b == b )
				return true;

		return false;
	}
	bool is_exists_first( const A & a )const
	{
		typename std::vector< pair >::const_iterator it = tab.begin();
		for( ; it != tab.end(); ++it )
			if( it->a == a )
				return true;

		return false;
	}
};

} // namespace liba

using namespace liba;

#endif //__SYMAP_H__